Ability to set the DefineConstraints of packages#733
Open
kochounoyume wants to merge 7 commits intoGlitchEnzo:masterfrom
Open
Ability to set the DefineConstraints of packages#733kochounoyume wants to merge 7 commits intoGlitchEnzo:masterfrom
kochounoyume wants to merge 7 commits intoGlitchEnzo:masterfrom
Conversation
JoC0de
requested changes
Apr 19, 2026
Co-authored-by: JoC0de <53140583+JoC0de@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for configuring Unity PluginImporter Define Constraints per NuGet package via packages.config, enabling conditional referencing based on scripting define symbols (feature #639, similar to #507’s autoReferenced support).
Changes:
- Parse and persist a new
defineConstraintsattribute inpackages.config. - Apply
defineConstraintsto imported package DLLs viaNugetAssetPostprocessor. - Document the new
defineConstraintssetting in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/NuGetForUnity/Editor/NugetAssetPostprocessor.cs | Applies package-level define constraints to Unity plugin importer settings. |
| src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs | Loads/saves defineConstraints from/to packages.config. |
| src/NuGetForUnity/Editor/Configuration/PackageConfig.cs | Adds DefineConstraints property to package config model. |
| README.md | Documents how to use defineConstraints in packages.config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+295
to
+298
| if (!string.IsNullOrWhiteSpace(packageConfig.DefineConstraints)) | ||
| { | ||
| plugin.DefineConstraints = packageConfig.DefineConstraints.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); | ||
| } |
Collaborator
There was a problem hiding this comment.
Good point two options:
- We accept this behaviour so user can manually set
DefineConstraintsin the unity settings (if he commits the .meta file to git) even when he doesn't use the setting in package-config. But unfortunately this will lead to the behaviour that a if a user uses the setting and later removes it frompackage.configit will not be applied. - We use the suggestion from Copilot -> a user that has set
DefineConstraintsin the .meta manually needs to mirror the setting to thepackage.config
JoC0de
approved these changes
Apr 19, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
JoC0de
requested changes
Apr 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the implementation of feature #639 .
Enabling the
DefineConstraintssetting allows you to, for example, set restrictions onUNITY_EDITORdefinitions for specific packages and exclude them from the build output.This proves extremely useful within the Unity environment.
Refer to the existing implementation; #507